function SOLUTION=Solver_Main(PP,StdVec,Options)
arguments
    PP struct;
    StdVec (7,1) double;
    Options.EqualWageFlag logical   =   1;
    Options.FileName char           =   '';
end
%% Steady State
if Options.EqualWageFlag
    [SS,PP]     =   SteadyState_Solver(PP);
else
    SS          =   SteadyState_Solver(PP,'EqualWageFlag',Options.EqualWageFlag);
end

%% Construct the Model Structure
MODEL       =   Setup_MODEL(PP,SS);

% Check the Steady State in Equation Blocks
Res_NK      =   Equ_NK(PP,SS,0);
Res_Portfolio=  Equ_Portfolio(PP,SS,MODEL,0);
Res_HH      =   Equ_HH(PP,SS,MODEL,0);

if max(abs([Res_NK;Res_Portfolio;Res_HH]))<1e-5
    fprintf('Steady State is Correct!\n');
else
    error('Steaty State is not Correct, check it  ...');
end


%% Compute the Jacobian
EquJac          =   struct();
EquJac.HH       =   Equ_HH(PP,SS,MODEL,1,[],[],1);
EquJac.HH_Aux   =   Equ_HH_Aux(PP,SS,MODEL,1,[],[],1);
EquJac.NK       =   Equ_NK(PP,SS,1);
EquJac.Portfolio=   Equ_Portfolio(PP,SS,MODEL,1,[],[],1);

%% IRF

% Flexible Exchange Rate
PP.Taylor_dE    =   0;

EquJac.NK       =   Equ_NK(PP,SS,1);
fir_ord         =   JacAssemble(MODEL,EquJac);
tic;
[gx,hx,gxhx_ExitFlag,gxhx_Info]=gx_hx(fir_ord,1);
fprintf(['Perturbation is Solved, Elapse Time=',num2str(toc,'%.2f'),'s\n']);
if gxhx_ExitFlag~=1
    warning('Perturbation Solution is problematic');
    SOLUTION    =   [];
    return
else
    solution    =   struct('gx',gx,'hx',hx);
    
end
% StdVec          =   [1 1 1 -1 -1 60]'*0.01/4;
IRF             =   IRF_1order(MODEL,solution,StdVec,[],4*20);

SOLUTION        =   struct('PP',PP,'SS',SS,'MODEL',MODEL,'EquJac',EquJac,...
                           'fir_ord',fir_ord,'gxhx',solution,'IRF',IRF);
if ~strcmp(Options.FileName,'')
    save([Options.FileName,'.mat'],'PP','SS','MODEL','EquJac','fir_ord','solution','IRF');
end